from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}


@app.post("/index/{sku_id}")
async def say_hello(sku_id: str):
    reversed_s = sku_id[::-1]  # 反转字符串
    total = 0

    for i in range(8):
        if i < len(reversed_s):
            total += ord(reversed_s[i])  # 获取 ASCII 值

    result = total % 32 if total is not None else 0
    return {"message": f"所在分片 {result}"}

@app.get("/outerid/{sku_id}")
async def say_slice_num(sku_id: str):
    reversed_s = sku_id[::-1]  # 反转字符串
    total = 0

    for i in range(8):
        if i < len(reversed_s):
            total += ord(reversed_s[i])  # 获取 ASCII 值

    result = total % 32 if total is not None else 0
    return {"message": f"所在分片 {result}"}


if __name__ == '__main__':
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=8000)
